
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QProcess>
#include<QDebug>
#include<QStringList>
#include<QString>
#include<windows.h>
#include<QScreen>
#include<QDate>
#include<QGuiApplication>
#include<QPixmap>
#include<QStandardPaths>


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

//    MainWindow::setWindowFlags(Qt::FramelessWindowHint);//隐藏边框

    //实现关机功能
    connect(ui->B1,&QToolButton::clicked,this,[=](){    QProcess process;
        process.start("cmd.exe", QStringList() << "/c" << "shutdown" << "/s" << "/t" << "0");

        if (!process.waitForFinished())
        {
            qDebug() << "Failed to shut down.";
        }
});

    //实现截图功能
    connect(ui->B2,&QToolButton::clicked,this,[=](){
        showMinimized();

        QScreen *screen = QGuiApplication::primaryScreen();



        QString desktop_path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);

        QString filePathName = desktop_path;

        qDebug()<<desktop_path;

        filePathName += "/full-";

        filePathName += QDateTime::currentDateTime().toString("yyyy-MM-dd hh-mm-ss-zzz");

        filePathName += ".jpg";

        qDebug()<<filePathName;

        showMaximized();

        if(!screen->grabWindow(0).save(filePathName, "jpg"))

        {

//            qDebug()<<"save full screen failed";

        }
    });

    //实现快速打开屏幕讲述人功能
    connect(ui->B3,&QToolButton::clicked,this,[=](){    QProcess process;
        process.start("cmd.exe", QStringList() << "/c" << "narrator");

        if (!process.waitForFinished())
        {
            qDebug() << "Failed to call narrator.";
        }
    });

    //实现快速打开设备管理器功能
    connect(ui->B4,&QToolButton::clicked,this,[=](){    QProcess process;
        process.start("cmd.exe", QStringList() << "/c" << "Devmgmt.msc");

        if (!process.waitForFinished())
        {
            qDebug() << "Failed to call narrator.";
        }
    });



}

MainWindow::~MainWindow()
{
    delete ui;

}






